<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
  components: {},
  data() {
    return {
      props: { multiple: true },
      appWindow: window,
      form: {},
      // 表格查询数据
      mixinTable_tableSearchData: {
        // 父参数
        // dictType: "",
      },
      // 表格数据
      tableData: [],
      loading: true,
      detailInfo: null,

      groups: [],
      groups_idLst: [],
      op_type: 0,
      id: [],

      form: {
        groupsIdLst: "",
      },

      editVisible: true,
    };
  },

  methods: {
    async submit() {
      this.loading = true;
      this.groups_idLst = []
      this.form.groupsIdLst.forEach(item => {
        if(item.length == 1){
          this.groups_idLst.push(item[0])
        }
        if(item.length == 2) {
          this.groups_idLst.push(item[1])
        }
      });
      let res = await this.$vFN.Http.post(
        {
          url: "store/goods/batch-groups",
          data: {
            groupsIdLst: this.groups_idLst,
            opType: this.op_type,
            productIdLst: this.id,
          },
        },
        window
      );

      if (res._ok) {
        this.editVisible = false;
        this.$vFN.Tools.messageSuccess("修改成功");
        this.onSuccess();
      }
    },

    // 初始化
    async init() {
      // 修改的商品id
      this.product_id.forEach((item) => {
        this.id.push(item.id);
      });
      // index为主页传来的参数
      if (this.index == 2) {
        // 数据源 分组
        this.groups = await this.$vFN.Tools.getSelectListSource(
          {
            url: "store/groups/index",
          },
          this.appWindow
        );
      }

      this.loading = false;
      this.editVisible = true;
    },

    // 提交成功
    onSubmitSuccess() {
      this.onSuccess();
    },
    // 成功回调
    onSuccess() {},
    // 取消回调
    onCancel() {
      this.editVisible = false;
    },
    // 失败回调
    onError() {},
  },
  mounted() {
    this.init();
  },
  activated() {},
};
</script>